package top.xiaoshuaila.searescue.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import top.xiaoshuaila.searescue.pojo.Serial;
import top.xiaoshuaila.searescue.pojo.Tag;
import top.xiaoshuaila.searescue.service.MqttDataDeal2;
import top.xiaoshuaila.searescue.service.MqttService;

@Controller
@RequestMapping("/index")
public class index {
    @Autowired
    private MqttService mqttService;
    @Autowired
    private Serial serial;
    @Autowired
    private setting setting;
    @Autowired
    private Tag tag;
    @Autowired
    private MqttDataDeal2 mqttDataDeal;
    @GetMapping("")
    public String hello1(Model model){
        model.addAttribute("asf","COM 1");
        return "index";
    }

    @GetMapping("/setSafe")
    @ResponseBody
    public void setSafe(int id){
        System.out.println(id+":"+tag.getTAG());
        id=tag.getTAG();
        System.out.println("safe:"+id);
        mqttService.Taskmsg=1;
        serial.setSystemStatus(0);
        setting.setSafe();
    }
    @GetMapping("/setQiangSafe")
    @ResponseBody
    public void setQiangSafe(int id){
        if(id==-1)
            id=tag.getTAG();
        tag.setTAG(id);
        serial.getQiangzhi().add(id);
        mqttDataDeal.lostTime.remove(id);
        setSafe(id);
    }
    @GetMapping("/setAlert")
    @ResponseBody
    public void setAlert(int id){
        tag.setTAG(id);
        System.out.println("alert:"+id);
        mqttService.Taskmsg=2;
        serial.setSystemStatus(1);
    }
    @GetMapping("/setQianAlert")
    @ResponseBody
    public void setQianAlert(int id){
        serial.getQiangzhi().add(id);
        setAlert(id);
    }
    @GetMapping("/jiechuqiangzhi")
    @ResponseBody
    public void setDanger(int id){
        mqttService.Taskmsg=0;
        serial.getQiangzhi().remove(id);
    }
}